#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtWidgets>
#include <QMap>
#include "qtermwidget.h"
#include "settingdialog.h"
#include "texteditor.h"
#include "xlsxdocument.h"

#define SSHIP 0
#define SSHUSER 1
#define SSHPASSWORD 2
#define DHCPLOGFILE 3
#define STARTSH 4
#define STOPSH 5
#define XLSXOUT 6
#define CONFIGOUT 7
#define SERVERIP 8

#define OPT_START 0
#define OPT_STOP 8

#define UPGRADEFRAMWORKFULLNAME 9
#define BOARDCONFIGFILEFULLNAME 10
#define LICENSESTRING 11
#define WIFIAPSSID 12
#define WIFIIP 13
#define MACSCAN 14

#define PARTITIONUBOOT 15
#define PARTITIONUBOOTENV 16
#define PARTITIONCFG1 17
#define PARTITIONCFG2 18
#define PARTITIONOME 19
#define PARTITIONDEFAULT 20
#define PARTITIONMFG 21
#define CURRENTPARTITION 22

#define STOP 22

#define SPECIALCMDEXIT STOP+1
#define SPECIALCMDSTARTSHELL STOP+2

#define TYPEKEY 0
#define LAN1KEY 1
#define LAN2KEY 2
#define CONFIGKEY 3
#define UPMTDKEY 4
#define MACKEY 5
#define LICENSEKEY 6
#define UPGRADEKEY 7
#define LEDKEY 8
#define WIFIKEY 9
#define RESETKEY 10
#define WATCHDOGKEY 11
#define CMDEXITSUCCESSKEY 12
#define CMDEXITFAILKEY 13
#define SSHLOGINKEY 14
#define CMDTIMEOUTFAILKEY 15

#define KEY_START 0
#define KEY_STOP 15

#define PASSKEY KEY_STOP+1
#define FAILKEY KEY_STOP+2
#define NAKEY KEY_STOP+3

#define NORMALKEY_END NAKEY
#define SPECIALLAN1CMD NORMALKEY_END+1
#define SPECIALLAN2CMD NORMALKEY_END+2
#define SPECIALCONFIGCMD NORMALKEY_END+3
#define SPECIALUPMTDCMD NORMALKEY_END+4
#define SPECIALMACCMD NORMALKEY_END+5
#define SPECIALLICENSECMD NORMALKEY_END+6
#define SPECIALUPGRADECMD NORMALKEY_END+7
#define SPECIALLEDCMD NORMALKEY_END+8
#define SPECIALWIFICMD NORMALKEY_END+9
#define SPECIALRESETCMD NORMALKEY_END+10
#define SPECIALWATCHDOGCMD NORMALKEY_END+11

#define SPECIALCMD_START NORMALKEY_END+1
#define SPECIALCMD_STOP NORMALKEY_END+11

#define PRODUCT_NAME_SS_2G12_8	 		"SS-2G12-8"
#define PRODUCT_NAME_SS_2G12_16			"SS-2G12-16"
#define PRODUCT_NAME_SS_5G16_8	 		"SS-5G16-8"
#define PRODUCT_NAME_SS_5G16_16			"SS-5G16-16"
#define PRODUCT_NAME_PB_5G20_8	 		"PB-5G20-8"
#define PRODUCT_NAME_PB_5G20_16			"PB-5G20-16"
#define PRODUCT_NAME_PB_5G23_8	 		"PB-5G23-8"
#define PRODUCT_NAME_PB_5G23_16			"PB-5G23-16"
#define PRODUCT_NAME_PB_5G25_8	 		"PB-5G25-8"
#define PRODUCT_NAME_PB_5G25_16			"PB-5G25-16"
#define PRODUCT_NAME_STATION5_8         "Station5-8"
#define PRODUCT_NAME_STATION5_16		"Station5-16"
#define PRODUCT_NAME_OS_5G12_8	 		"OS-5G12-8"
#define PRODUCT_NAME_OS_5G12_16			"OS-5G12-16"
#define PRODUCT_NAME_DB_5G25_8	 		"DB-5G25-8"
#define PRODUCT_NAME_DB_5G25_16			"DB-5G25-16"


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QString get_ip_from_dhcp_log();
    void default_setting();
    QString get_cur_time_and_date();
    bool run_vjjt_test_script(QString fileName);
    bool autodetect_dhcpd_log_file();
    bool is_current_month_and_day(QString Month, QString Day);
    bool check_dhcpoffer_ip(QString ip);
    bool tryload_config(QString config_file);
    void xlsx_save(QString);
    bool start_ssh_connection();
    bool run_one_cmd(QString cmd);
    QString filter_cmd_line(QString line);
    void pick_up_result(QString text);
    QString filter_result(QString text);
    QString generate_license(QString license);

protected:
    void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;

signals:
    void cmd_result(QString res);

private slots:
    void on_startService_clicked();
    void update_time();
    void emit_success_result_timer();
    void emit_fail_result_timer();
    void on_StopService_clicked();
    void on_actionAbout_triggered();
    void on_actionAbout_Qt_triggered();
    void on_actionExit_triggered();
    void on_actionExport_To_Excel_triggered();
    void on_actionSetting_triggered();
    void on_actionSSH_Connect_triggered();
    void on_actionRandom_Mac_Address_Generotor_triggered();
    void on_actionTarget_Board_IP_AutoDetector_triggered();
    void on_actionSave_Config_File_triggered();
    void on_actionLoad_Config_File_triggered();
    void on_actionText_Editor_triggered();
    void on_actionAll_Config_triggered();
    void capture_from_qterm(QString text);
    void cmd_result_slot(QString res);
    void on_devtypebox_currentTextChanged(const QString &arg1);

private:
    Ui::MainWindow *ui;
    bool is_run_one_cmd_next;
    bool run_one_cmd_res;
    void connect_capture_to_handler();
    QString last_capture;
    QString capture_buf;
    QString last_ip;

    SettingDialog *settingdialog;
    TextEditor *texteditor;
    QStringList all_dev_type_name;
    QTimer *timer;
    QTimer *delay_success_timer;
    QTimer *delay_fail_timer;

    int dev_count;
    QString dev_type;

    bool is_config;
    QMap<QString, QString> data_map;
    QMap<int, QString> opt_map;
    QMap<int, QString> capture_key_map;

    bool is_edit_tablewidget;
    bool is_detect_ip;
    bool is_ssh;
};

#endif // MAINWINDOW_H
